<?php

class Core_Backend_Component_Subject_View_Category_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('subject/category/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('cateogry_form')
                ->addHiddenField('id', 'category[id]');
        $form->addTextboxField($this->__('share.label.name'), 'name', 'category[name]', TRUE)->addRequiredRule();
        $form->addTextboxField($this->__('share.label.sef_url'), 'sef_url', 'category[sef_url]');
        $form->addSelectField($this->__('share.label.theme'), 'theme_id', "category[theme_id]")
             ->bindData($this->getThemes(), 'title', 'id');
        $form->addComboTreeField($this->__('subject.label.parent_category'), 'parent_id', "category[parent_id]")
             ->bindData($this->getParentCategories()->toArray(), 0, array('valueKey'=>'id', 'textKey'=>'name', 'parentKey'=>'parent_id', 'childKey'=>'id'))
             ->setDefaultOption('', '--');
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}